/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
    struct ListNode* tailA = headA,*tailB = headB;
    int lenA= 1,lenB = 1;
    //A链表的尾
    while(tailA->next)
    {
        tailA =  tailA->next;
        lenA++;
    }
    //B链表的尾
    while(tailB->next)
    {
        tailB = tailB->next;
        lenB++;
    }
    //不相交
    if(tailA != tailB)
    return NULL;
    //相交情况
    //差距步
    int gap = abs(lenA - lenB);

    //不知道谁长，假设法
    struct ListNode* longer = headA, *shorter = headB;
    if(lenA<lenB)
    {
        longer = headB;
        shorter = headA;
    }
    //长的先走差距步
    while(gap--)
    {
        longer = longer->next;
    }
    while(longer != shorter)
    {
        longer = longer->next;
        shorter = shorter->next;
    }
    return longer;
    
}